package qj.app.console;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import qj.util.Cols;
import qj.util.SystemUtil;
import qj.util.funct.P0;

public class Config implements Serializable {
	public Integer selected;
	public List<Console> consoles;

	public Map<String,Map<String,String>> invokerConfigs;
	
	transient
	public P0 saveF;
	
	public Config() {
		consoles = new ArrayList<Console>();

		consoles.add(gaeConsole());
		consoles.add(gaeConsole());
		consoles.add(jbossConsole());
		
		invokerConfigs = new HashMap<String, Map<String,String>>();
		if (SystemUtil.isWindows()) {
			invokerConfigs.put("gae", Cols.<String,String>map("gae.home","c:/Applications/appengine-java-sdk-1.6.5"));
		} else {
//			invokerConfigs.put("gae", Cols.<String,String>map("gae.home","/home/quanle/Apps/appengine-java-sdk-1.6.2.1"));
			invokerConfigs.put("gae", Cols.<String,String>map("gae.home","/Users/quanle/Applications/appengine-java-sdk-1.6.5"));
		}
	}
	
	public void init() {
		for (Console console : consoles) {
			console.saveF = new P0() {public void e() {
				saveF.e();
			}};
		}
	}

	private Console gaeConsole() {
		Console console = console("Google App Engine", "gae");
		if (SystemUtil.isWindows()) {
			console.properties = Cols.map(
					"war.home","C:/Workon/qj-svn/commercial-apps/gunny-tool/taikhoan-qn/data/web",
					"port","80"
					);
		} else {
			console.properties = Cols.map(
					"war.home","/home/quanle/Workon/qj-svn/commercial-apps/gunny-tool/taikhoan-qn/data/web",
					"port","8080"
					);
		}
		return console;
	}
	private Console jbossConsole() {
		Console console = console("JBoss", "jboss");
		console.properties = Cols.map("jboss.home","d:/Quan/Apps/jboss-4.2.3.GA_Minh/jboss");
		return console;
	}

	private Console console(String name, String type) {
		Console console = new Console();
		console.name = name;
		console.type = type;
		return console;
	}
	
	public static class Console implements Serializable {
		public String name;
		public String type;
		public Map<String,String> properties;
		transient
		public P0 saveF;
	}

	public P0 saveDetailF(String type) {
		return saveF;
	}
}
